package com.collaboration.electron.controllers;

import com.collaboration.electron.entities.*;
import com.collaboration.electron.services.ProductService;
import com.collaboration.electron.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.security.Principal;
import java.util.List;

/**
 * @author lydia
 * @param
 * @return 无
 */

@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    ProductService productService;

    @GetMapping("")
    public String displayUser(Model model, Principal principal){
        String name = principal.getName();
        model.addAttribute("name",name);

        U u = userService.findByUserName(name);
        long Id = u.getUserId();

        List<U> us =userService.getAll();
        model.addAttribute("users", us);

        List<Product> products=productService.getAll();
        model.addAttribute("products",products);
        return "user";
    }

//    @GetMapping("/new")
//    public String displayUserFrom(Model model){
//        U auser=new U();
//        model.addAttribute("user",auser);
//        return "new-user";
//    }

//    @PostMapping ("/save")
//    public String creatUser(Model model, U u){
//
//        userService.save(u);
//        return "redirect:user/new";
//
//    }



}
